﻿using System;
using System.Net.Sockets;
using UnityEngine.Events;

namespace Elvex
{
    public abstract class NetSession
    {
        protected Socket m_socket;

        public UnityEvent OnError { get; } = new UnityEvent();

        public UnityEvent<byte[]> OnReceive { get; } = new UnityEvent<byte[]>();

        public NetSession(Socket socket)
        {
            m_socket = socket;
            NetManager.Instance.AddSession(this);
        }

        public void Stop()
        {
            m_socket.Close();
        }

        public abstract bool Deliver(byte[] buffer);
    }
}
